<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('入库单据管理')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
<!--                        <li>-->
<!--                            <label class="is-required">仓库：</label>-->
<!--                            <select id="warehouseId" name="warehouseId" th:with="type=${session.warehouse}">-->
<!--                                &lt;!&ndash;								<option   th:value="${session.warehouseId}" th:text="${@dict.getDictLabel('${session.warehouseId}')}"></option>&ndash;&gt;-->
<!--                                <option th:each="dict : ${type}" th:text="${dict.warehouseName}" th:value="${dict.warehouseId}"></option>-->
<!--                            </select>-->
<!--                        </li>-->

                        <li>
                            <label>仓库：</label>
                            <select name="warehouseId" th:with="type=${@dict.getType('is_house')}" required>
                                <!--<option value="">请选择</option>-->
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="status" th:with="type=${@dict.getType('dj_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>入库类型：</label>
                            <select name="inType" th:with="type=${@dict.getType('dj_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>单据编号：</label>
                            <input type="text" name="stockinId"/>
                        </li>
                        <li>
                            <label>下发单号：</label>
                            <input type="text" name="FID"/>
                        </li>
                        <li>
                            <label>建单时间：</label><input type="text" placeholder="请单击选择开始时间：" autocomplete="off"
                                                       name="createDate" id="createDate"/>---
                            <input type="text" placeholder="请单击选择结束时间：" autocomplete="off" name="finishDate"
                                   id="finishDate"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm"
                               onclick="$.table.search('formId','bootstrap-table')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm"
                               onclick="$.form.reset('formId','bootstrap-table')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--                <a class="btn btn-success btn-xs " onclick="audit(2)" >-->
            <!--                <i class="fa fa-upload"></i> 单据审核-->
            <!--                </a>-->
            <!--                <a class="btn btn-success btn-xs " onclick="receive()" >-->
            <!--                <i class="fa fa-upload"></i> 到货确认-->
            <!--                </a>-->
            <a class="btn btn-success btn-xs" onclick="audit(4)">
                <i class="fa fa-download"></i> 单据确认
            </a>
            <a class="btn btn-danger" onclick="audit(5)">
                <i class="fa fa-trash-o"></i> 单据作废
            </a>
            <a class="btn btn-success" onclick="printProduct()">
                <i class="fa fa-plus"></i> 打印条码
            </a>
            <!--<a class="btn btn-danger" onclick="handleBack()" >
            <i class="fa fa-trash-o"></i> 手动回传
            </a>-->
        </div>
        <div id="div1" class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
        <div class="col-sm-8 select-table">
            <table id="bootstrap-table2" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: LodopFuncs_js"></th:block>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('in:stockin:edit')}]];
    var removeFlag = [[${@permission.hasPermi('in:stockin:remove')}]];
    var inTypeDatas = [[${@dict.getType('dj_type')}]];
    var statusDatas = [[${@dict.getType('dj_status')}]];
    var stockinSource = [[${@dict.getType('stockin_source')}]];
    var productStatus = [[${@dict.getType('product_status')}]];
    var warehouseIdDatas = [[${@dict.getType('is_house')}]];
    var prefix = ctx + "in/stockin";

    layui.use('laydate', function () {
        var laydates = layui.laydate;
        laydates.render({
            elem: '#createDate'
            , type: 'datetime',
            /* ,range: '到' */
            format: 'yyyy-MM-dd HH:mm:ss'
        })
    })

    layui.use('laydate', function () {
        var laydates = layui.laydate;
        laydates.render({
            elem: '#finishDate'
            , type: 'datetime',
            /* ,range: '到' */
            format: 'yyyy-MM-dd HH:mm:ss'
        })
    })

    $(function () {
        var options = {
            url: prefix + "/list",
            auditUrl: prefix + "/audit",
            modalName: "单据管理",
            clickToSelect: true,//是否启用点击选中行
            singleSelect: true,
            search: false,
            uniqueId: "stockinId",//表主键(用于修改和删除)
            sortName: "createDate",//必加排序
            sortOrder: "desc",//默认
            columns: [
                {
                    halign: 'center',
                    align: 'center',
                    checkbox: true
                },
                {
                    title: "序号",
                    halign: 'center',
                    align: 'center',
                    width: 55,
                    formatter: function (value, row, index) {
                        //获取每页显示的数量
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
                        //获取当前是第几页
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
                        //返回序号，注意index是从0开始的，所以要加上1
                        return pageSize * (pageNumber - 1) + index + 1;

                    }
                },

                {
                    field: 'stockinGuid',
                    title: 'UUID',
                    halign: 'center',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'stockinId',
                    title: '单据编号',
                    halign: 'center',
                    align: 'center',
                    visible: true
                },{
                    field: 'fid',
                    title: '下发单号',
                    halign: 'center',
                    align: 'center',
                    visible: true
                },
                {
                    field: 'lineId',
                    title: '暂存订单号',
                    halign: 'center',
                    align: 'center',
                    visible: true
                },

                {
                    field: 'inType',
                    title: '入库类型',
                    halign: 'center',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(inTypeDatas, value);
                    }
                },

                {
                    field: 'status',
                    title: '状态',
                    halign: 'center',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'stockinSource',
                    title: '单据来源',
                    halign: 'center',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(stockinSource, value);
                    }
                },
                {
                    field: 'createManId',
                    title: '建单人',
                    halign: 'center',
                    align: 'center',
                    visible: true
                },

                {
                    field: 'warehouseId',
                    title: '所属仓库',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(warehouseIdDatas, value);
                    }
                },

                {
                    field: 'createDate',
                    title: '建单时间',
                    halign: 'center',
                    align: 'center',
                    visible: true
                },
                {
                    field: 'classNowId',
                    title: '当前班组',
                    halign: 'center',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'lineId',
                    title: '产线',
                    halign: 'center',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'finishDate',
                    title: '完成时间',
                    halign: 'center',
                    align: 'center',
                    visible: true
                },
            ],
            //双击显示子表
            onClickRow: function (t, e) {
                // initSubTable(index, row, $detail);
                options2.url = ctx + "in/stockindetail/list?stockinId=" + t.stockinId + "&stockinGuid=" + t.stockinGuid;
                $('#bootstrap-table2').bootstrapTable("refresh", options2)
            },
            onLoadSuccess(data) {
                switch (data.code) {
                    case  500:
                        options2.url = "";
                        $('#bootstrap-table').bootstrapTable("removeAll");
                        $('#bootstrap-table2').bootstrapTable("removeAll");
                        $.modal.alertWarning("查询出错！");
                        break;
                    default:
                        $('#bootstrap-table2').bootstrapTable("removeAll");
                        break;
                }
            },
        };
        $.table.init(options);
    });
    //子表
    var options2 = {
        url: "",
        singleSelect: true,
        search: false,
        showRefresh: true,
        showColumns: true,
        minimumCountColumns: 2,
        clickToSelect: true,//是否启用点击选中行
        sortName: "stockinDetailId",
        sortOrder: "asc",
        modalName: "入库单据子表",
        method: 'post',
        height: $("#div").height() / 1,
        striped: true, //是否显示行间隔色
        pagination: false,//显示分页
        sidePagination: "client",
        pageNumber: 1,
        pageSize: 15,
        pageList: [10, 25],
        columns:
            [{
                checkbox: true,
            },
                {
                    field: 'stockinDetailId',
                    title: '子表编号'
                },
                {
                    field: 'stockinGuid',
                    title: '主表guid',
                    visible: false
                },
                {
                    field: 'stockinId',
                    title: '主表编号',
                    sortable: false
                },
                {
                    field: 'productId',
                    title: '物料编码',
                    align: 'center'
                },
                {
                    field: 'productName',
                    title: '物料名称',
                    align: 'center'
                },
                {
                    field: 'lotNo',
                    title: '批次号',
                    align: 'center'
                },
                {
                    field: 'printDate',
                    title: '生产时间',
                    align: 'center'
                },
                {
                    field: 'unit',
                    title: '单位',
                    visible: true
                }, {
                    field: 'stockStatus',
                    title: '物料状态',
                    visible: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(productStatus, value);
                    }
                },
                {
                    field: 'productGuid',
                    title: '物资guid',
                    visible: false
                }, {
                    field: 'supplierId',
                    title: '供应商',
                    visible: true
                },{
                    field: 'cargoNo',
                    title: '暂存单托盘码',
                    visible: true
                }, {
                    field: 'assignNum',
                    title: '重量',
                    visible: true
                },
                {
                    field: 'quantity',
                    title: '开单数量',
                    align: 'center'
                },
                {
                    field: 'quantityX',
                    title: '扫码数量',
                    align: 'center',
                    visible: true
                },
                {
                    field: 'quantityJ',
                    title: '入库数量',
                    align: 'center',
                    visible: true
                }
            ],
        onLoadSuccess(data) {
            switch (data.code) {
                case  500:
                    options2.url = "";
                    $('#bootstrap-table2').bootstrapTable("removeAll")
                    $.modal.alertWarning("查询出错！");
                    break;
                default:
                    break;
            }
        },
    }
    $('#bootstrap-table2').bootstrapTable(options2)

    function audit(status) {
        var mm = "";
        if (status == 2) {
            mm = "审核";
        } else if (status == 4) {
            mm = "确认";
        } else if (status == 5) {
            mm = "作废";
        }
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        if (rows.length > 1) {
            $.modal.alertWarning("只允许选择一条记录！");
            return;
        }
        $.modal.confirm("确认要" + mm + "选中的" + rows.length + "条单据吗?", function () {
            var url = table.options.auditUrl;
            var data = {"ids": rows.join(), "status": status};
            $.operate.submit(url, "post", "json", data);
        });
    }


    //打印条码
    function printProduct() {

        var checkedItems = $("#bootstrap-table").bootstrapTable('getSelections');
        if (checkedItems.length == 0) {
            $.modal.alertWarning("请至少选择一条子单据信息");
            return;
        }
        LODOP = getLodop(document.getElementById('LODOP_OB'), document
            .getElementById('LODOP_EM'));
        LODOP.SET_SHOW_MODE("LANGUAGE", 0);
        LODOP.PRINT_INITA(20, 40, 2400, 1800, "WMS单据号");
        LODOP.SET_PRINT_PAGESIZE(1, "100mm", "60mm", "");
        LODOP.SET_PRINT_MODE("POS_BASEON_PAPER",true);
        LODOP.SET_PRINT_MODE("AUTO_CLOSE_PREWINDOW", 1);//打印后自动关闭预览窗口(2019-1-30)


        for (let i = 0; i < checkedItems.length; i++) {
            LODOP.NewPage();
            //window.alert(checkedItems[i].FID);
            LODOP.PRINT_INITA(10,10,1000,700,"单据号");
            // LODOP.SET_PRINT_PAGESIZE(1,800,500,"0");
            // LODOP.SET_PRINT_MODE("AUTO_CLOSE_PREWINDOW",true);
            LODOP.ADD_PRINT_BARCODE(20, 177, 120, 120, "QRCode", checkedItems[i].fid);
            LODOP.ADD_PRINT_TEXT(10, 20, 72, 20, "单据号:");
            LODOP.ADD_PRINT_TEXT(30, 20, 120, 20, checkedItems[i].fid);
            /*LODOP.ADD_PRINT_TEXT(30, 20, 66, 20, "物料编码:");
            LODOP.ADD_PRINT_TEXT(30, 78, 140, 20, checkedItems[i].productId);
            LODOP.ADD_PRINT_TEXT(50, 20, 64, 20, "物料名称:");
            LODOP.ADD_PRINT_TEXT(50, 79, 125, 20, checkedItems[i].productName);
            LODOP.ADD_PRINT_TEXT(70, 20, 66, 20, "比 例 号:");
            LODOP.ADD_PRINT_TEXT(70, 78, 120, 20, checkedItems[i].price);
            LODOP.ADD_PRINT_TEXT(90, 20, 70, 20, "单    位:");
            LODOP.ADD_PRINT_TEXT(90, 79, 124, 20, checkedItems[i].unit);
            LODOP.ADD_PRINT_TEXT(110, 20, 67, 20, "开单数量:");
            LODOP.ADD_PRINT_TEXT(110, 79, 121, 20, checkedItems[i].quantity);*/
        }
        LODOP.PREVIEW();
        //新建打印页面
        // LODOP.PRINT_DESIGN();
    }

    //手动回传
    function handleBack() {

        var checkedItems = $("#bootstrap-table").bootstrapTable('getSelections');
        if (checkedItems.length == 0) {
            $.modal.alertWarning("请至少选择一条子单据信息");
            return;
        }
        // alert(checkedItems[0].fid);
        $.ajax({
            url: "/in/stockin/handleBack",
            method: "POST",
            data: JSON.stringify({
                fid: checkedItems[0].fid,
                classNowId:1
            }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                // 处理响应结果
                console.log(result);
                alert(result.msg)
                window.location.reload();
            },
            error: function (xhr, status, error) {
                // 处理错误信息
                console.log(error);
            }
        });
    }
</script>
</body>
</html>